import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: () => import('@/views/HomeView')
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/auth/Register'),
    meta: {title: '注册'}
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/error/404'),
    meta: {title: '404-NotFound'}
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/auth/Login'),
    meta: {title: '登录'}
  },
  {
    path: '/post/create',
    name: 'post-create',
    component: () => import('@/views/post/Create'),
    meta: {title: '发布' ,  requireAuth: true}
  },
  //帖子详情
  {
    path: '/post/:id',
    name: 'post-detail',
    component: () => import('@/views/post/Detail'),
    meta: {title: '帖子详情'}
  },
  //编辑帖子
  {
    path: '/topic/edit/:id',
    name: 'topic-edit',
    component: () => import('@/views/post/Edit'),
    meta: {title: '编辑' , requireAuth: true}
  },
  {
    path: '/topic/:name',
    name: 'tag',
    component: () => import('@/views/tag/Tag'),
    meta: { title: "主题列表" }
  },
  //搜索
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/Search'),
    meta: {title: '搜索'}
  },
  //用户主页
  {
    path: '/member/:username/home',
    name: 'user',
    component: () => import('@/views/user/Profile'),
    meta: {title: '用户主页'}
  },
  //用户设置
  {
    path: '/member/:username/setting',
    name: 'user-setting',
    component: () => import('@/views/user/Setting'),
    meta: {title: '用户设置'}
  }, 
  //后天管理
  {
    path: '/member/:username/admin',
    name: 'user-admin',
    component: () => import('@/views/user/admin'),
    meta: {title: '后台管理'}
  }, 
  {
    path: '*',
    redirect: '/404',
    hidden: true
  },
]

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err);
};

const router = new VueRouter({
  routes
})

export default router
